package DemoText;

/**
 * Pow( x, n )递归
 */
public class LeetCode50 {
    public double myPow(double x, int n) {
        return n >= 0 ? my_pow( x, n ) : 1.0 / my_pow( x, -n );
    }
    public double my_pow(double x, int n) {
        if ( n == 0 ) return 1.0;
        double tmp = my_pow( x, n / 2);
        return n % 2 == 0 ? tmp * tmp : tmp * tmp * x;
    }
}
